<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>更新武侠</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all"/>
</head>
<body>
<!--弹出层-->
<div class="layui-row" id="open_div">
    <form id="add_form" class="layui-form" action="" style="margin-top: 20px;align:center;">
        <!--隐藏字段action，用来区分增加和编辑行为-->
        <input type="hidden" name="action" id="action">
        <!--隐藏字段id，用于提供编辑需要的主键-->
        <input type="hidden" name="id" id="id">
        <!--隐藏字段request_type，用于提供请求方式:get,post,put-->
        <input type="hidden" name="request_type" id="request_type">

        <div class="layui-form-item" style="display: table;width: 96%">
            <div class="layui-form-item" style="display: table-cell;width: 50%">
                <label class="layui-form-label">姓&emsp;&emsp;名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" placeholder="请输入武侠姓名"
                           autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>

            <div class="layui-form-item" style="display: table-cell;width: 50%">
                <label class="layui-form-label">年&emsp;&emsp;龄</label>
                <div class="layui-input-block">
                    <input type="text" name="age" placeholder="请输入武侠年龄"
                           autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>
        </div>

        <div class="layui-form-item" style="display: table;width: 96%">
            <div class="layui-form-item" style="display: table-cell;width: 50%">
                <label class="layui-form-label">性&emsp;&emsp;别</label>
                <div class="layui-input-block">
                    <select name="skill" lay-filter="sex" lay-verify="required">
                        <option value="">请选择</option>
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" style="display: table-cell;width: 50%">
                <label class="layui-form-label">门&emsp;&emsp;派</label>
                <div class="layui-input-block">
                    <input type="text" name="sect" placeholder="请输入武侠门派"
                           autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="display: table;width: 96%">

            <div class="layui-form-item" style="display: table-cell;width: 50%">
                <label class="layui-form-label">绝&emsp;&emsp;技</label>
                <div class="layui-input-block">
                    <input type="text" name="sex" placeholder="请输入武侠绝技"
                           autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>
            <div class="layui-form-item" style="display: table-cell;width: 50%">
                <label class="layui-form-label">战&ensp;力&ensp;值</label>
                <div class="layui-input-block">
                    <input type="text" name="power" placeholder="请输入武侠战力值"
                           autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>

        </div>
        <div class="layui-form-item" style="display: table;width: 96%">
            <div class="layui-form-item" style="display: table-cell;">
                <label class="layui-form-label">地&emsp;&emsp;址</label>
                <div class="layui-input-block">
                    <input type="text" name="address" placeholder="请输入地址"
                           autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 40%">
            <div class="layui-btn-group">
                <button class="layui-btn" lay-submit="" lay-filter="update_submit">提&ensp;交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重&ensp;置</button>
            </div>
        </div>
    </form>
</div>

<!--引用js-->
<script src="../layui/layui.js"></script>
<script src="../js/lib/jquery-2.1.1.min.js"></script>
<script src="../utils/common.js"></script>

<script>
    layui.use(['table', 'layer', 'form', 'laypage'], function () {
        var form = layui.form;

        // 监听表单提交
        form.on('submit(update_submit)', function (data) {
            console.log(data);
            $.ajax({
                type: "post",
                url: '/person/addPerson',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data.field),
                dataType: "json",
                // 成功回调
                success: function (result) {
                    if (result.code == "0") {
                        layer.msg('新增成功！', {icon: 1, time: 2000});
                    } else {  //失败
                        layer.alert(result.msg, {icon: 2});
                    }
                }
            });
            return false; //表示表单不跳转
        });
    });
</script>

</body>
</html>